package com.erp.controller.baseDataController;

import com.erp.pojo.Account;
import com.erp.service.baseDataService.AccountService;
import com.erp.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 * Author:${JayC}
 * Date:2019/1/19
 * Time:10:25
 */
@RestController
@RequestMapping("/Account")
public class AccountController {

    @Autowired
    private AccountService accountService;
    //查询
    @PostMapping("/getAcc")
    public Msg getInout(@RequestParam(name = "name",defaultValue = "")String name,
                        @RequestParam(name = "type",defaultValue = "")String serialno,
                        @RequestParam(name = "page")int page,
                        @RequestParam(name = "limit")int limit){

        Msg inout = accountService.getAcc(name, serialno, page, limit);

        return inout;

    }
    //删除
    @DeleteMapping("/delAccount/{id}")
    public void deleteInout(@PathVariable(name = "id")Long id){
        accountService.deleteAcc(id);
    }

    //多条删除
    @DeleteMapping("/delAccounts/{ids}")
    public void delInouts(@PathVariable(name = "ids")String ids){
        String a[] = ids.split(",");
        System.out.println(Arrays.toString(a));

        for (int i = 0; i < a.length; i++) {
            Long id = Long.valueOf(a[i]);
            accountService.deleteAcc(id);

            System.out.printf("进入删除控制器");
        }
    }

    //增加
    @PostMapping("/insertInout")
    public void insertInout(Account account){
        accountService.insertAcc(account);
    }
}
